Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Can anyone tell me why i get error ".toFixed is not a function"
import React from "react";
import { useContext } from "react";
import styled from "styled-components";
import { GlobalContext } from "../context/GlobalState";
import IncomeTransactions from "./IncomeTrasactions";

function Head() {

In this part, I draw a month and a year

  let months = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
  ];
  let mY = new Date();
  let monthName = months[mY.getMonth()];
  const current = new Date();
  const date = `${current.getFullYear()}`;
  const { incomeTransactions, expenseTransactions } = useContext(GlobalContext);

  const incomeAmounts = incomeTransactions.map(
    (incomeTransaction) => incomeTransaction.incomeAmount
  );
  const expenseAmounts = expenseTransactions.map(
    (expenseTransaction) => expenseTransaction.expenseAmount
  );

In this section, I get an error "expenseAmounts.reduce(...).toFixed is not function"

const totalIncome = incomeAmounts
    .reduce((acc, item) => (acc += item), 0)
    .toFixed(2);

  const totalExpense = expenseAmounts
    .reduce((acc, item) => (acc += item), 0)
    .toFixed(2);

The code below is ok and everything works, the problem is somewhere I marked it return ( Available Budget in {monthName} {date}

{totalIncome - totalExpense}.00

Income

            <div>+ {totalIncome}</div>
          </div>
          <div className="expenses-top mt-3">
            <div>Expenses</div>

            <div>- {totalExpense}</div>
          </div>
        </BlockHeader>

        <ImageHeader src="/img/header-budget.png" />
      </Wrap>
    </div>
  );
}

export default Head;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!